package slice

import "errors"

func Delete[T any](src []T, index int) ([]T, T, error) {
	length := len(src)
	if length < 0 || index >= length {
		var zero T
		return nil, zero, errors.New("out of index")
	}

	j := 0

	rst := src[index]

	for i, v := range src {
		if i != index {
			src[j] = v
			j++
		}
	}

	src = src[:j]

	return src, rst, nil
}
